/*
  This is the driver of our modeling program. Here is where we start the main.
  The one command line argument that needs to be passed is the speed the car will 
  be traveling at during the legs of the race.
*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "/usr/include/math.h"
#include "ssm_conversions.h"
//#include "ssm_3.h"
#include "ssm.h"

extern FILE *fd;

int main(int argc, char *argv[]) 
{
	//double ddistance;	// change in dist (distance) for current time step
	Simulation sim;		//simulation data, read in from sim.str
	Race race;		//race data, read in from race.str
	Dynamic d;		//dynamic data, read in from dynamic.str
	Car c;			//car data, read in from car.str
	Weather weather;	//weather data, read in from weather.str
	Route route;		//route data, this route data is represented as 
				//legs in a race, hence is implemented using an array of legs
	//double speed;	not used//speed you are traveling, given my user

	if(argc != 4) 
	{
 		fprintf(stderr,"ERROR: Usage ./ssm route_file plan_file data_file\n");
  		exit(1);
	}

	
	/*
		The next block of code reads in the default values from the files
		The functions were implemented by Ian Smith.
		These are used later to simulate the route
		This assumes that the program setStructures has already been ran
		and that the defaults are already set
	*/

	read_route(argv[1], argv[2], &route);
	readSim("sim.str", &sim);
	readRace("race.str", &race);
	readCar("car.str", &c);
	readDynamic("dynamic.str", &d);
	readWeather("weather.str", &weather);

	fd = fopen(argv[3], "w+");		//Where to store the results of the simulation
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//initialize simulation
	//initializeSimulation(speed, &race, &sim, &d, &c, &weather);
	//printHeader(race, sim, d, weather, c);
	//simLoop(&race, &sim, &d, &c, &weather);


	routeLoop(&race, &sim, &d, &c, &weather, &route);	//this function is stored in modeling.c. It actually does 
								//the most work, and runs the simulation
	fclose(fd);
								//It is stored in modeling.c and assumes that gnuplot package is installed
	exit(0);  
}


